//
//  ViewBaseViewController+BusinessDataRequest.m
//  
//
//  Created by JingXing Wu on 12-3-30.
//  Copyright (c) 2012年 GuangZhouXuanWu. All rights reserved.
//

#import "UIViewController+BusinessDataRequest.h"

#import "UIViewController+ProgressView.h"

NSString *const XUIViewControllerBusinessDataRequestNetWorkOfflineTip = @"当前网络不可用，请检查你的网络设置";

@implementation UIViewController (BusinessDataRequest)

- (void)beginProgressView:(XMSDataOperationManager *)dom
{
    if (YES == [self respondsToSelector:@selector(beginProgressViewPanel)])
        [self beginProgressViewPanel];
}

- (void)endProgressView:(XMSDataOperationManager *)dom
{
    if (YES == [self respondsToSelector:@selector(endProgressViewPanel)])
        [self endProgressViewPanel];
}

- (void)holdProgressView:(XMSDataOperationManager *)dom delayTime:(NSTimeInterval)nDelay
{
    if (YES == [self respondsToSelector:@selector(setProgressViewPanelReleaseDelayTime:)])
        [self setProgressViewPanelReleaseDelayTime:nDelay];
}

- (void)beginProgressView:(XMSDataOperationManager *)dom funcationName:(NSString *)szFuncationname
{
    [self beginProgressView:dom];
}

- (void)endProgressView:(XMSDataOperationManager *)dom funcationName:(NSString *)szFuncationname
{
    [self endProgressView:dom];
}

- (void)beginProgressViewWithTip:(NSString *)tip
{
    if (YES == [self respondsToSelector:@selector(beginProgressViewPanel:)])
        [self beginProgressViewPanel:tip];
}

-(void)filterRequestResult:(NSInteger)requestResult defaultError:(NSError*)error noFilter:(void(^)(NSInteger requestResult))noFilter
{
    switch(requestResult)
    {
        case TERMINATEREADWRITE:
        {
            break;
        }
        case NETWORKOFFLINE:
        {
            if([self selfIsTopViewController])
                [UIAlertView showErrorMsg:XUIViewControllerBusinessDataRequestNetWorkOfflineTip];
            break;
        }
        case PROTOCOLRETOBJNIL:
        {
            if([self selfIsTopViewController])
                [UIAlertView showErrorMsg:error.domain];
            break;
        }
        default:
        {
            noFilter(requestResult);
            break;
        }
    }
}

@end
